﻿using Sustainalytics.DataLayer.ConnectionStrings;
using Sustainalytics.Entities.ConnectionStrings;
using Sustainalytics.Universes.BusinessLogic;
using System;
using System.Web.Http;
using System.Net;
using Sustainalytics.ClientDW.DataAccessLayer;
using System.Configuration;
using System.Net.Http;
using System.Web.Http.Cors;

namespace Sustainalytics.Universes.Service.Controllers
{
    [EnableCors(origins: "*", headers: "*", methods: "*")]
    [RoutePrefix("api/v1/universes")]
    public class UniversesController : ApiController, IUniversesController
    {
        private readonly IUniversesManagement _universesManagement;

        public UniversesController(IUniversesRepository universesRepository, IUniversesManagement universesManagement)
        {
            try
            {
                _universesManagement = universesManagement;
            }
            catch (Exception)
            {

                throw new HttpResponseException(HttpStatusCode.InternalServerError);
            }
        }

        [Route("{id}")]
        public HttpResponseMessage Get(Guid id)
        {
            try 
	        {
                return Request.CreateResponse(HttpStatusCode.OK, _universesManagement.GetUniversesByAccountId(id).ConvertAll<object>(univ => UniverseDto.CreateWithIdName(univ)));
	        }
	        catch (Exception)
	        {
                throw new HttpResponseException(HttpStatusCode.NotFound);
	        }
        }

    }
}
